package com.heima.wemedia.service.controller;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmNewsDto;
import com.heima.model.wemedia.dto.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2022-04-12 19:20:45
 */
@RestController
@RequestMapping("/api/v1/news/")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 自媒体文章发布 , 修改 , 保存草稿
     *
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * 查询文章列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.list(dto);
    }

    /**
     * 查询单个文章详情
     *
     * @param id
     * @return
     */
    @GetMapping(path = "/one/{id}")
    public ResponseResult one(@PathVariable("id") Long id) {
        WmNews wmNews = wmNewsService.queryById(id);
        return ResponseResult.okResult(wmNews);
    }

    @GetMapping(path = "del_news/{id}")
    public ResponseResult delete(@PathVariable("id") Long id) {
        return wmNewsService.deleteById(id);
    }

}

